package patrol.mobile.com.mobilepatrol.activity.monitor;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.bean.DateBean;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.DatePickerUtil02;
import patrol.mobile.com.mobilepatrol.utils.TimeUtils;
import patrol.mobile.com.mobilepatrol.utils.ToastUtils;
import patrol.mobile.com.mobilepatrol.view.CallBack;

import static patrol.mobile.com.mobilepatrol.utils.SPUtils.get;

/**
 * Created by z on 2018/9/18.
 * Des: 机电巡检编辑页面
 */

public class JdxjEditActivity extends BaseActivity {
    @BindView(R.id.editDanweiName)
    TextView editDanweiName;
    @BindView(R.id.editUserName)
    TextView editUserName;
    @BindView(R.id.editTime)
    TextView editTime;
    @BindView(R.id.nextText)
    TextView nextText;
    @BindView(R.id.setTimeLayout)
    LinearLayout setTimeLayout;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_jdxh_edit_layout;
    }

    @Override
    public void initTitle() {
        super.initTitle();
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText(R.string.bianjiyemian);
        editUserName.setText(UserManager.getUser((String) get(Constants.current_id, "")).ryname);
        editDanweiName.setText(UserManager.getUser((String) get(Constants.current_id, "")).bmname);
        editTime.setText(TimeUtils.dateString4(System.currentTimeMillis()));
    }

    @Override
    public void setListener() {
        nextText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(v.getContext(), XjMingXiMuBanActivity.class)
                        .putExtra("xunjianren", editUserName.getText().toString())
                        .putExtra("riqi", editTime.getText().toString())
                );
                finish();
            }
        });

        setTimeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickerUtil02.getInstance(v.getContext()).setCallBack(new CallBack<DateBean>() {
                    @Override
                    public void onBack(DateBean dateBean) {
                        editTime.setText(dateBean.getmDate());
                    }
                });
            }
        });
    }
}
